home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / library / __tioctl.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  7KB  |  278 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  __tioctl.c,v 1.1.1.1 1994/04/04 04:30:13 amiga Exp
  20.  *
  21.  *  __tioctl.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:13  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.5  1993/11/05  21:51:08  mw
  26.  *  seems I got oldstyle tty handling oposite way..
  27.  *
  28.  *  Revision 1.4  1992/08/09  20:39:01  amiga
  29.  *  add a cast to get rid of a warning
  30.  *
  31.  *  Revision 1.3  1992/07/04  19:07:25  mwild
  32.  *  send DISK_INFO packet with synchronous port, async delivery seems to be
  33.  *  broken with CNC:
  34.  *
  35.  * Revision 1.2  1992/06/08  02:36:00  mwild
  36.  * fix TIOCGWINSZ, row/column was off by one
  37.  *
  38.  * Revision 1.1  1992/05/14  19:55:40  mwild
  39.  * Initial revision
  40.  *
  41.  */
  42.  
  43. #define KERNEL
  44. #include "ixemul.h"
  45. #include "kprintf.h"
  46. #include <string.h>
  47. #include <sgtty.h>
  48.  
  49. #define OEXTB 15
  50. #undef B0    
  51. #undef B50    
  52. #undef B75    
  53. #undef B110    
  54. #undef B134    
  55. #undef B150    
  56. #undef B200    
  57. #undef B300    
  58. #undef B600    
  59. #undef B1200    
  60. #undef B1800    
  61. #undef B2400    
  62. #undef B4800    
  63. #undef B9600    
  64. #undef EXTA    
  65. #undef EXTB    
  66. #include <sys/termios.h>
  67. #include <ctype.h>
  68. #include <devices/conunit.h>
  69. #include <intuition/intuition.h>
  70.  
  71. /* IOCTLs on "interactive" files */
  72.  
  73. int
  74. __tioctl(struct file *f, unsigned int cmd, unsigned int inout, 
  75.      unsigned int arglen, unsigned int arg)
  76. {
  77.   int omask, result, err = 0;
  78.  
  79.   omask = syscall (SYS_sigsetmask, ~0);
  80.   __get_file (f);
  81.   result = -1;
  82.  
  83.   if (!f->f_fh->fh_Port)
  84.     {
  85.       err = ENOTTY;
  86.       goto ret;
  87.     }
  88.  
  89.   switch (cmd)
  90.     {
  91.     case TIOCGETA:
  92.       {
  93.         struct termios *t = (struct termios *)arg;
  94.         unsigned char *cp;
  95.         t->c_iflag = IGNBRK | IGNPAR | IXON;
  96.     if (f->f_ttyflags & IXTTY_ICRNL)
  97.       t->c_iflag |= ICRNL;
  98.     if (f->f_ttyflags & IXTTY_INLCR)
  99.       t->c_iflag |= INLCR;
  100.         t->c_oflag = 0;
  101.     if (f->f_ttyflags & IXTTY_OPOST)
  102.       t->c_oflag |= OPOST;
  103.     if (f->f_ttyflags & IXTTY_ONLCR)
  104.       t->c_oflag |= ONLCR;
  105.         t->c_cflag = CS8|CLOCAL;
  106.         t->c_ispeed=
  107.         t->c_ospeed= EXTB;
  108.     /* Conman does ECHOCTL, Commo doesn't.. I use Conman:-)) */
  109.         t->c_lflag = ECHOCTL | ((f->f_ttyflags & IXTTY_RAW) ? 0 : ICANON | ECHO);
  110.     cp = t->c_cc;
  111.     cp[VSTART] = 'q' & 31;
  112.     cp[VSTOP] = 's' & 31;
  113.     cp[VSUSP] = 0; /* sneef.. would that be nice... */
  114.     cp[VDSUSP] = 0;
  115.     cp[VREPRINT] = 0;
  116.     cp[VDISCARD] = 'x' & 31;
  117.     cp[VWERASE] = 0;
  118.     cp[VLNEXT] = 0;
  119.     cp[VSTATUS] = 0;
  120.     cp[VINTR] = 3;
  121.     cp[VQUIT] = 0;
  122.     cp[VERASE] = 8;
  123.     cp[VKILL] = 'x' & 31;
  124.     cp[VEOF] = '\\' & 31;
  125.     cp[VEOL] = 10;
  126.     cp[VEOL2] = 0;
  127.     result = 0;
  128.     goto ret;
  129.       }
  130.  
  131.     case TIOCSETA:
  132.     case TIOCSETAW:
  133.     case TIOCSETAF:
  134.       {
  135.         struct termios *t = (struct termios *)arg;
  136.         int makeraw;
  137.         
  138.         makeraw = (t->c_lflag & (ICANON | ECHO)) != (ICANON | ECHO);
  139.     /* the only thing that counts so far.. if ICANON is disabled,        
  140.      * we disable ECHO too, no matter what the user wanted, and 
  141.      * send a RAW-packet.. */
  142.     if (!makeraw && (f->f_ttyflags & IXTTY_RAW))
  143.           {
  144.         f->f_ttyflags &= ~IXTTY_RAW;
  145.         __wait_packet(&f->f_sp);
  146.         SendPacket1(f, __rwport, ACTION_SCREEN_MODE, 0);
  147.         __wait_packet(&f->f_sp);
  148.       }
  149.     else if (makeraw && !(f->f_ttyflags & IXTTY_RAW))
  150.       {
  151.         f->f_ttyflags |= IXTTY_RAW;
  152.         __wait_packet(&f->f_sp);
  153.         SendPacket1(f, __rwport, ACTION_SCREEN_MODE, -1);
  154.         __wait_packet(&f->f_sp);
  155.       }
  156.     if (t->c_iflag & ICRNL)
  157.       f->f_ttyflags |= IXTTY_ICRNL;
  158.     else
  159.       f->f_ttyflags &= ~IXTTY_ICRNL;
  160.     if (t->c_iflag & INLCR)
  161.       f->f_ttyflags |= IXTTY_INLCR;
  162.     else
  163.       f->f_ttyflags &= ~IXTTY_INLCR;
  164.     result = 0;
  165.     goto ret;
  166.       }
  167.  
  168.     case TIOCGETP:
  169.       {
  170.     struct sgttyb *s = (struct sgttyb *)arg;
  171.     s->sg_erase = 8;
  172.     s->sg_kill = 'x' & 31;
  173.     s->sg_flags = ODDP|EVENP|ANYP|
  174.               ((f->f_ttyflags & IXTTY_RAW) ? (CBREAK|RAW) : (ECHO|CRMOD));
  175.     s->sg_ispeed =
  176.     s->sg_ospeed = OEXTB;
  177.     result = 0;
  178.     goto ret;
  179.       }
  180.  
  181.     case TIOCSETN:
  182.     case TIOCSETP:
  183.       {
  184.     struct sgttyb *s = (struct sgttyb *)arg;
  185.     if (!(s->sg_flags & (RAW|CBREAK)))
  186.           {
  187.             f->f_ttyflags &= ~IXTTY_RAW;
  188.         __wait_packet(&f->f_sp);
  189.         SendPacket1(f, __rwport, ACTION_SCREEN_MODE, 0);
  190.         __wait_packet(&f->f_sp);
  191.       }
  192.         else if ((s->sg_flags & (RAW|CBREAK)))
  193.       {
  194.         f->f_ttyflags |= IXTTY_RAW;
  195.         __wait_packet(&f->f_sp);
  196.         SendPacket1(f, __rwport, ACTION_SCREEN_MODE, -1);
  197.         __wait_packet(&f->f_sp);
  198.       }
  199.     result = 0;
  200.     goto ret;
  201.       }
  202.  
  203.     case TIOCGWINSZ:
  204.       {
  205.     struct winsize *ws = (struct winsize *) arg;
  206.     struct ConUnit *cu;
  207.     struct IOStdReq *ios;
  208.     struct InfoData *info;
  209.     struct Window *w;
  210.  
  211.     err = EINVAL;    /* default */
  212.     
  213.     info = alloca (sizeof (struct InfoData) + 2);
  214.     info = LONG_ALIGN (info);
  215.     bzero (info, sizeof (struct InfoData));
  216.     
  217.     /* VERY! strange.. CNC: won't act on the packet if it sent with the
  218.        async port as reply port! The error is OBJECT_IN_USE (202)... */
  219.  
  220.     __wait_packet (&f->f_sp);
  221.     LastResult (f) = 0; LastError (f) = 0;
  222.     SendPacket1 (f, u.u_sync_mp, ACTION_DISK_INFO, CTOBPTR (info));
  223.     __wait_sync_packet (&f->f_sp);
  224.     if (LastResult (f) != -1)
  225.           goto ret;
  226.  
  227.     w = (struct Window *) info->id_VolumeNode;
  228.     if (! w) 
  229.       goto ret;
  230.     /* this information is from DevCon notes, not from the Bantam book */
  231.     ios = (struct IOStdReq *) info->id_InUse;
  232.     if (! ios || ((int)ios & 1)) 
  233.       goto ret;
  234.     cu = (struct ConUnit *) ios->io_Unit;
  235.     if (!cu) 
  236.       goto ret;
  237.  
  238.     /* paranoid check.. */
  239.     if (cu->cu_Window != w)
  240.       goto ret;
  241.  
  242.         ws->ws_xpixel = w->Width - w->BorderLeft - w->BorderRight;
  243.         ws->ws_ypixel = w->Height - w->BorderTop - w->BorderBottom;
  244.  
  245.     ws->ws_col = cu->cu_XMax + 1;    /* Thanks Rob! those values are off */
  246.     ws->ws_row = cu->cu_YMax + 1;    /* by one! */
  247.  
  248.     result = 0;
  249.     goto ret;
  250.       }
  251.  
  252.     case TIOCOUTQ:
  253.       {
  254.     int *count = (int *)arg;
  255.  
  256.     *count = 0;
  257.     result = 0;
  258.     goto ret;
  259.       }
  260.  
  261.     case TIOCSWINSZ:
  262.       /* should I really try to resize the window ?? */
  263.  
  264.     default:
  265.       /* this is no error, but nevertheless we don't take any actions.. */      
  266.       result = 0;
  267.       goto ret;
  268.     }
  269.  
  270. ret:
  271.     LastResult(f) = 0;
  272.     __release_file (f);
  273.     syscall (SYS_sigsetmask, omask);
  274.     errno = err;
  275.     KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  276.     return result;
  277. }
  278.